﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YahooManaged.Finance;

namespace download
{
    class Start
    {
        static void Main(string[] args)
        {
            ////下载
            //string[] ids = new string[] {
            //        "SINA"//, "BIDU", "SFUN", "BONA",
            //        //"CYOU", "NTES", "SNDA", "YOKU", "GA",
            //        //"TUDO", "DANG", "SOHU", "LONG", "QIHU",
            //        //"PWRD", "JOBS", "KUTV", "KONG", "RENN",
            //};
            //DateTime toDate = DateTime.Today;
            //DateTime fromDate = toDate.AddDays(-3650); //约10年
            //HistQuotesDataChain[] res = null;
            //Download.DownloadData(ids, fromDate, toDate, ref res);
            //// 存文件
            //foreach (HistQuotesDataChain qd in res)
            //{
            //    Download.SaveData(qd, qd.ID + ".txt");
            //}
            //if (true)  当数据未下载到本地，可以去掉本注释
            //    return;
            // 读文件
            HistQuotesDataChain cur_qd = null;
            Download.LoadData(ref cur_qd, "test.txt");
            // 分析
            Ana ana = new Ana(cur_qd);
            DateTime from = DateTime.ParseExact("20090605", "yyyyMMdd", null);
            DateTime to = DateTime.ParseExact("20110527", "yyyyMMdd", null);
            // random baseline
            double gain = 0;
            for (int i = 0; i < 100; i++)
                gain += ana.RandomStrategy(from, to);
            gain /= 100;  // baseline
            Console.WriteLine("random baseline gain=" + gain);
            // 长期持有Baseline
            double hold = ana.HoldStrategy(from, to);
            Console.WriteLine("hold gain=" + hold);
            // 寻找新高
            double bt = ana.Breakthrough(from, to);
            Console.WriteLine("breakthrough gain=" + bt);
            // macd
            double macd = ana.MacdStrategy(from, to);
            Console.WriteLine("macd gain=" + macd);
        }
    }
}
